import java.util.LinkedList;
import java.util.Queue;

public class SolutionOffer13 {
    public int movingCount(int m, int n, int k) {
        int[] dx={1,0,-1,0};
        int[] dy={0,1,0,-1};
        Queue<int[]> queue=new LinkedList<>();
        queue.offer(new int[]{0,0});
        int ans=1;
        boolean[][] visit=new boolean[m][n];
        visit[0][0]=true;
        while (!queue.isEmpty()){
            int[] q=queue.poll();
            for (int i=0;i<4;i++){
                int x=q[0]+dx[i];
                int y=q[1]+dy[i];
                if (x>=0 && x<m && y>=0 && y<n && !visit[x][y] && cal(x)+cal(y)<=k){
                    ans++;
                    visit[x][y]=true;
                    queue.offer(new int[]{x,y});
                }
            }
        }
        return ans;
    }

    private int cal(int x) {
        String t=String.valueOf(x);
        int ans=0;
        for (char c : t.toCharArray()) {
            ans=ans+c-'0';
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionOffer13().movingCount(2,3,1));
    }

}
